import Vue from "vue"
import Vuex from "vuex"
Vue.use(Vuex)
import { userInfo } from "@/api"

const store = new Vuex.Store({
	state: {
		userInfo: {},
		isLogin: false
	},
	getters: {},
	mutations: {
		SET_USER_INFO(state, userInfo) {
			state.userInfo = userInfo
		},
		SET_LOGIN(state, falg) {
			state.isLogin = falg
		}
	},
	actions: {
		userInfo({ commit }) {
			return userInfo().then(res => {
				commit('SET_USER_INFO', res.data.user)
				commit('SET_LOGIN', true)
				wx.setStorageSync('userInfo', res.data.user)
				return Promise.resolve(res.data.user)
			})
		}
	}
})


export default store